package xp2p.svc.file;

import net.jxta.content.ContentTransferEvent;
import net.jxta.content.ContentTransferListener;
import net.jxta.content.ContentTransferState;

public class TransferListener implements ContentTransferListener
{
	private String name;
	private TransferCompleteHandler handler; 
	
	public TransferListener(String name, TransferCompleteHandler fileDownloader)
	{
		this.setName(name);
		this.handler = fileDownloader;
	}
	
	@Override
	public void contentLocationStateUpdated(ContentTransferEvent event)
	{
		Integer location = event.getSourceLocationCount();
		System.err.println(location);
		System.err.println(location);
		System.err.println(location);
	}

	@Override
	public void contentTransferProgress(ContentTransferEvent event)
	{
		ContentTransferState state = event.getTransferState();
		Integer location = event.getSourceLocationCount();
		System.err.println(state.toString());
		System.err.println(location);
		System.err.println(location);
		System.err.println(location);		
	}

	@Override
	public void contentTransferStateUpdated(ContentTransferEvent event)
	{
		ContentTransferState state = event.getTransferState();
		Integer location = event.getSourceLocationCount();
		System.err.println(state.toString());
		System.err.println(location);
		System.err.println(location);
		System.err.println(location);
		if (event.getTransferState() == ContentTransferState.COMPLETED)
		{
			handler.complete(name);
		}		
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

}
